/*
 * @Author: HeAo
 * @Date: 2021-09-29 09:10:10
 * @LastEditTime: 2021-09-29 09:24:19
 * @LastEditors: HeAo
 * @Description:
 * @FilePath: \web2103-2105\web2103code\3-1-ES6\day05\1-promise.js
 * 别乱动！
 */
const promise = new Promise(function (resolve, reject) {
  if (1 > 0) {
    const response = {
      status: 200,
      message: '操作成功',
      data: null,
      timestamp: new Date().getTime()
    }
    resolve(response)  // promise内部状态由padding => fulfilled
  } else {
    const response = {
      status: 500,
      message: '后台接口异常',
      data: null,
      timestamp: new Date().getTime()
    }
    reject(response)  // promise内部状态由padding => rejected
  }
})

// promise成功之后，调用resolve(),对应就是.then()内部的回调
// promise失败之后，调用reject(),对应就是.catch()内部的回调
// promise实例直接调用.then.catch，这种用法叫链式调用
promise.then((res) => {
  console.log(res);
}).catch((err) => {
  console.log(err);
})